/*
 * Copyright 2018-2019 KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain menu_text_color copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.wanchuang.hepos.bridge.state.main;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableBoolean;
import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.wanchuang.architecture.utils.ValidateUtils;
import com.wanchuang.hepos.bridge.data.bean.UserBean;
import com.wanchuang.hepos.help.GlideHelper;
import com.wanchuang.hepos.proto.Bank;
import com.wanchuang.hepos.proto.MemberOuterClass;
import com.wanchuang.hepos.ui.view.easyadapter.RecyclerArrayAdapter;
import com.wanchuang.hepos.ui.web.ui.WebViewActivity;

import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.bgabanner.BGABanner;

/**
 * TODO tip：每个页面都要单独准备一个 statusViewModel，
 * 来托管 DataBinding 绑定的临时状态，以及视图控制器重建时状态的恢复。
 * <p>
 * 如果这样说还不理解的话，详见 https://xiaozhuanlan.com/topic/9816742350
 * <p>
 * Create by KunMinX at 19/10/29
 */
public class HomeFragmentViewModel extends ViewModel {
    public final ObservableField<BGABanner.Adapter<ImageView, String>> bannerAdapter = new ObservableField<>();

    public final ObservableArrayList<String> bannerFeedList = new ObservableArrayList<>();
    public final ObservableArrayList<String> bannerTitleList = new ObservableArrayList<>();
    public final ObservableField<String> amount_today = new ObservableField<>();
    public final ObservableField<String> limit_toady = new ObservableField<>();
    public final ObservableField<String> num_today = new ObservableField<>();
    public final ObservableField<String> amount_total = new ObservableField<>();
    public final ObservableField<String> limit_total = new ObservableField<>();
    public final ObservableField<String> num_total = new ObservableField<>();
    public final ObservableField<String> pm_text = new ObservableField<>();
    public final ObservableField<String> wallet_d0 = new ObservableField<>();
    public final ObservableField<String> wallet_t1 = new ObservableField<>();
    public final ObservableField<String> wallet_temp = new ObservableField<>();
    public final ObservableField<String> wallet_total = new ObservableField<>();
    public final ObservableField<String> wallet_weichu = new ObservableField<>();





    public final ObservableBoolean sys_switch = new ObservableBoolean();
    public final ObservableBoolean sys_ji_fen = new ObservableBoolean();
    public final ObservableBoolean agency_switch = new ObservableBoolean();
    public final ObservableBoolean wx_switch = new ObservableBoolean();
    public final ObservableBoolean ll_switch = new ObservableBoolean();
    public String point_html_url = "";
    public List<Bank.bank> banks = new ArrayList<>();

    {
        sys_switch.set(true);
        bannerAdapter.set((banner, itemView, model, position) ->
                {
                   String[]  split =  model.split(",");
                    GlideHelper.INSTANCE.loadFitXYImage(itemView,split[0]);
                    itemView.setOnClickListener(v -> {
                        if (ValidateUtils.isValidate(split[1])) {  //  关联类型：0无跳转，1链接跳转，2视频详情页跳转
                            if (split[1].contains("http"))
                                WebViewActivity.startActivity(banner.getContext(), split[1]);
                        }
                    });
                }
        );

    }
}
